﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;

public partial class admin_Edit_editor_upload : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request["cmd"] != null && Request["cmd"].ToString() == "upload")
        {
            String upfileDir = Request.PhysicalApplicationPath + "admin\\uploadfile\\";
            Int32 maxSize = 50;
            ArrayList arr = new ArrayList();
            String type = Request["uploadtype"].ToString();
            if (type == "img")
            {
                arr.Add("jpg");
                arr.Add("bmp");
                arr.Add("png");
                arr.Add("gif");
            }
            if (type == "attach")
            {
                arr.Add("rar");
                arr.Add("zip");
            }
            HttpPostedFile files = Request.Files["file1"];
            String name = files.FileName.Substring(files.FileName.LastIndexOf("\\") + 1);
            String fileExt = name.Substring(name.LastIndexOf(".") + 1).ToLower();
            if (!arr.Contains(fileExt))
                Page.ClientScript.RegisterClientScriptBlock(GetType(), "key", "<script>alert('不允许上传该类型的文件！');window.parent.document.getElementById('divProcessing').style.display='none';history.back();</script>", false);
            if (files.ContentLength > maxSize * 1024)
                Page.ClientScript.RegisterClientScriptBlock(GetType(), "key", "<script>alert('文件过大！');window.parent.document.getElementById('divProcessing').style.display='none';history.back();</script>", false);
            name = "[" + DateTime.Now.ToString("yyyyMMddHHmmss") + "]-" + name;
            files.SaveAs(upfileDir + name);
            if (type == "img")
            {
                Page.ClientScript.RegisterClientScriptBlock(GetType(), "key", "<script>window.parent.LoadIMG('../uploadfile/" + name + "');</script>", false);
            }
            else if (type == "attach")
            {
                Page.ClientScript.RegisterClientScriptBlock(GetType(), "key", "<script>window.parent.LoadAttach('../uploadfile/" + name + "');</script>", false);
            }
        }
    }
}